package com.blocks.blocks;

import com.blocks.ScriptBlocksApplication;
import com.blocks.model.BlockSides;
import com.blocks.script.ScriptUtils;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;

public class MasterBlock extends Block{

	public MasterBlock(String name, Long masterBlockId) {
		super(name, masterBlockId);
	}
	@Override
	public void init() {
		setTextureRow(0.0f);
		setTextureColumn(2.0f);
		 super.init();
		
	}
	
	public Material getDefaultMaterial() {
		Material defaultMaterial = super.getDefaultMaterial();
		//defaultMaterial.setColor("Color", ScriptBlocksApplication.getInstance().getColorRGBA());
		return defaultMaterial;
		
	}

    
	
	@Override
	public void updateLogicalState(float tpf) {
		
		super.updateLogicalState(tpf);
		if(this.getLocalTranslation().getY()<2.0f){
			this.setLocalTranslation(this.getLocalTranslation().add(new Vector3f(0.0f, 1.0f, 0.0f)));
		}
	}
	public void setPowered(boolean powered) {
		super.setPowered(powered);
		if(powered){
			this.getMaterial().setColor("Color", ColorRGBA.Green);
		}else {
			this.getMaterial().setColor("Color", ColorRGBA.Gray);	
		}
	}
	@Override
	public void use(){
		this.updatePower(!this.isPowered());
	}
	
//	public RigidBodyControl getPhysicsControl(){
//		return this.getControl(com.jme3.bullet.control.RigidBodyControl.class);
//	}
	

	
	@Override
	public int getParentFrequency(BlockSides blockSides) {
		return 0;
	}
	@Override
	public String scriptExport() {
		StringBuffer sb = new StringBuffer();
		sb.append(super.scriptExport());
		return sb.toString();
	}
	

	
	
}
